package com.mininglamp.service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.mininglamp.crud.OrderCrud;
import com.mininglamp.mapper.OrderMapper;
import com.mininglamp.model.Orders;
import com.mininglamp.utils.DateUtils;
import com.mininglamp.utils.Pager;

@Service
public class OrderService {
	
	@Autowired
	OrderCrud orderCrud;
	
	@Autowired
	OrderMapper orderMapper;
	
	/**
	 * 新增订单
	 * @param order
	 * @return
	 */
	public int insertOrder(Orders order){

		if(order!=null)
		{
			orderCrud.save(order);
			return 1;
		}else{
			return 0;
		}
	}
	/**
	 * 分页查询订单
	 * @param wetChatId
	 * @param pager
	 * @return
	 */
	public Pager findPageOrders(String wetChatId,Pager pager){
		PageBounds pageBounds = new PageBounds(pager.getPageNum(),pager.getPageSize());
		PageList<Orders> pageList = orderMapper.findPageOrders(wetChatId, pageBounds);
		
		pager.setDatas(pageList);
		pager.setTotalNum(pageList.getPaginator().getTotalCount());
		return pager;
		
	}
	/**
	 * 根据微信号查询所有订单
	 * @param wetchatId
	 * @return
	 */
	public List<Orders> findByWetchasId(String wetchatId){
		
		return orderCrud.findByWetchatId(wetchatId);
		
	}

}
